//
//  LGSijiHomeViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/24.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGGongJiViewController.h"
#import "LGHomeTableViewCell.h"
#import "LGJiBaiRankViewController.h"
#import "LGSiJiCreateViewController.h"
#import "LGGongJiHistoryRankViewController.h"
#import "LGGongJiDetailViewController.h"
@interface LGGongJiViewController ()

@end

@implementation LGGongJiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"私祭";
    [self configSubView];
    [self st_setRightItemWithImage:[UIImage imageNamed:@"纪念馆添加icon"]];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 20)];
    UIImageView * bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 156)];
    bannerImageView.image = [UIImage imageNamed:@"祠堂banner"];
    [header addSubview:bannerImageView];
    
    NSArray * array = @[@{@"title":@"历史伟人",@"imageName":@"历史伟人"},
                        @{@"title":@"政治军事",@"imageName":@"政治军事"},
                        @{@"title":@"中华烈士",@"imageName":@"中华烈士"},
                        @{@"title":@"感动中国",@"imageName":@"感动中国"},
                        @{@"title":@"自然科学",@"imageName":@"自然科学"},
                        @{@"title":@"艺术文艺",@"imageName":@"艺术文艺"},
                        @{@"title":@"国家公祭墙",@"imageName":@"国家公祭墙"},
                        ];
    CGFloat buttonWith = UIScreenWidth / 4;
    for (NSInteger i =0 ;i < array.count;i ++) {
        NSDictionary * dic = array[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        __weak typeof(self) weakSelf =  self;
        STMenuControl * menuControl = [[STMenuControl alloc] initWithFrame:CGRectMake(0, bannerImageView.bottom, buttonWith, buttonWith) imageName:imageName title:title titleColor:FirstTextColor];
        [menuControl setOnSelctedControl:^(STMenuControl *control) {
            [weakSelf onSelctedMenuControlWithTitle:title];
        }];
        [header addSubview:menuControl];
        
        menuControl.left = i%4 * buttonWith;
        menuControl.top = i/4 * buttonWith + bannerImageView.bottom;
        header.height = menuControl.bottom;
    }
  //  header.height = bannerImageView.bottom + buttonWith;
    self.tableView.tableHeaderView = header;
    
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGHomeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 44;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * view = [TMUtils headerViewWithTitle:@"推荐陵园"];
    return view;
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LGGongJiDetailViewController * vc = [LGGongJiDetailViewController new];
    [self.navigationController pushViewController:vc animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)st_rightBarAction:(id)sender{
    LGSiJiCreateViewController * vc = [LGSiJiCreateViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onSelctedMenuControlWithTitle:(NSString*)title{

    LGGongJiHistoryRankViewController * vc = [LGGongJiHistoryRankViewController new];
    vc.title = title;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
